﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Collections;
using Ss.Model;

namespace Vici.Mvc
{
    public abstract partial class Controller
    {
        #region 导入相关资源文件
        /// <summary>
        /// 导入Jq
        /// </summary>
        public void IncludeJq()
        {
            View.RegisterJavascriptInclude("Jquery", false, "~/App_Themes/Scripts/Jquery/jquery-1.6.4.js");
        }
        /// <summary>
        /// 导入IdealForm
        /// </summary>
        public void IncludeIdealForm()
        {
            View.RegisterCSSInclude("~/App_Themes/Scripts/idealForm/css/normalize.css");
            View.RegisterCSSInclude("~/App_Themes/Scripts/idealForm/css/idealForms/idealforms.css");
            View.RegisterCSSInclude("~/App_Themes/Scripts/idealForm/css/master.css");
            View.RegisterJavascriptInclude("idealForms", false, "~/App_Themes/Scripts/idealForm/js/jquery.idealforms.js");
            View.RegisterJavascriptInclude("scripts", false, "~/App_Themes/Scripts/idealForm/js/scripts.js");
        }
        /// <summary>
        /// 加载EasyUI
        /// </summary>
        public void IncludeEasyUi()
        {
            View.RegisterCSSInclude("~/App_Themes/Scripts/EasyUI/themes/default/easyui.css");
            View.RegisterCSSInclude("~/App_Themes/Scripts/Easyui/themes/icon.css");
            View.RegisterJavascriptInclude("easyui", false, "~/App_Themes/Scripts/EasyUI/jquery.easyui.min.js");
            View.RegisterJavascriptInclude("laneasyui", false, "~/App_Themes/Scripts/EasyUI/locale/easyui-lang-zh_CN.js");
            View.RegisterJavascriptInclude("easyloader", false, "~/App_Themes/Scripts/Easyui/easyloader.js");

        }
        /// <summary>
        /// 加载ParallaxSlider
        /// </summary>
        public void IncludeParallaxSlider()
        {
            View.RegisterCSSInclude("~/App_Themes/Scripts/ParallaxSlider/css/style.css");
            View.RegisterJavascriptInclude("ParallaxSlider", false, "~/App_Themes/Scripts/ParallaxSlider/js/ParallaxSlider.js");
        }
        /// <summary>
        /// 加载easyvalidator验证器
        /// </summary>
        public void IncludeValid()
        {
            View.RegisterCSSInclude("~/App_Themes/Scripts/easyvalidator/css/validate.css");
            View.RegisterJavascriptInclude("easy_validator", false, "~/App_Themes/Scripts/easyvalidator/js/easy_validator.pack.js");
            View.RegisterJavascriptInclude("bgiframe", false, "~/App_Themes/Scripts/easyvalidator/js/jquery.bgiframe.min.js");
        }
        /// <summary>
        /// 加载通用JS
        /// </summary>
        public void IncludeCommonJs()
        {
            View.RegisterJavascriptInclude("Common", false, "~/App_Themes/Scripts/Common.js");
        }
        /// <summary>
        /// 加载JQ Form
        /// </summary>
        public void IncludeJqForm()
        {
            View.RegisterJavascriptInclude("form", false, "~/App_Themes/Scripts/JqueryForm/jquery.form.js");
        }
       
        #endregion
        #region 网站属性
        /// <summary>
        /// 网站的名字
        /// </summary>
        /// <returns></returns>
        public string SiteName
        {
            get { return SiteInfo.ReadSafe(1).SiteName; ; }
            set
            {
                SiteInfo si = SiteInfo.ReadSafe(1);
                si.SiteName = value;
                si.Save();
            }
        }
        /// <summary>
        /// 网站的描述
        /// </summary>
        /// <returns></returns>
        public string SiteDescription
        {
            get { return SiteInfo.ReadSafe(1).SiteDescription; ; }
            set
            {
                SiteInfo si = SiteInfo.ReadSafe(1);
                si.SiteDescription = value;
                si.Save();
            }
        }
        /// <summary>
        /// 网站的关键字
        /// </summary>
        /// <returns></returns>
        public string SiteKeywords
        {
            get { return SiteInfo.ReadSafe(1).SiteKeywords; ; }
            set
            {
                SiteInfo si = SiteInfo.ReadSafe(1);
                si.SiteKeywords = value;
                si.Save();
            }
        }

    
        #endregion
        #region WEB方法
        /// <summary>
        /// 需要发送的对象
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public DictionaryEntry[] SendObj(object obj)
        {

            Hashtable temp = new Hashtable();
            foreach (PropertyInfo o in obj.GetType().GetProperties())
            {
                temp.Add(o.Name, o.GetValue(obj, null));
            }
            DictionaryEntry[] array = new DictionaryEntry[temp.Count];
            temp.CopyTo(array, 0);
            return array;
        }
        /// <summary>
        /// 接受对象
        /// </summary>
        /// <param name="obj">接受的对象</param>
        /// <param name="getObj">发送的对象</param>
        public object GetObj(object obj, DictionaryEntry[] getObj)
        {

            foreach (PropertyInfo user in obj.GetType().GetProperties())
            {
                DictionaryEntry ss = getObj.Where(p => p.Key.ToString() == user.Name).FirstOrDefault();
                if (ss.Key == null) continue;
                PropertyInfo[] t = obj.GetType().GetProperties();
                PropertyInfo s = t.Where(p => p.Name == ss.Key.ToString()).FirstOrDefault();
                s.SetValue(obj, ss.Value.ToString(), null);
            }
            return obj;
        }
        #endregion
    }
}
